﻿
@using Newtouch.Infrastructure;
@using Newtouch.Tools;
@{
	ViewBag.Title = "Index";
	Layout = "~/Views/Shared/_Index.cshtml";
}

<form>
	<div class="panel panel-default">
		<div class="panel-heading navb-bg">
			筛选条件
		</div>
		<table class="form">
			<tr>
				<th class="formTitle"></th>
				<td class="formValue" colspan="2">
					<input type="radio" name="radios" class="radios" value="qb" checked="checked">全部
					<input type="radio" name="radios" class="radios" value="yd">已对码
					<input type="radio" name="radios" class="radios" value="wd">未对码
				</td>
				<th class="formTitle">药品名称：</th>
				<td class="formValue" colspan="2">
					<input id="txt_keyword" type="text" style="width:200px;" class="form-control form-an" placeholder="药品名称">
				</td>
				<td class="formValue">
					<input type="button" id="btn_search" class="btn btn-primary" style="width:36%;margin-left: 10%;" value="查询" />
				</td>
				<th class="formTitle"></th>
				<td class="formValue"></td>
				<th class="formTitle"></th>
				<td class="formValue"></td>
			</tr>
		</table>
	</div>
	<div class="gridPanel">
		<table id="gridList"></table>
		<div id="gridPager"></div>
	</div>
	<div class="panel panel-default">
		<div class="toolbar" style="margin-left:2%">
			<div class="btn-group">
				<label>医保药品名称：</label>
			</div>
			<div class="btn-group">
				<input id="txt_gjybdm" type="text" style="width:200px; height:20px;" class="form-control form-an" placeholder="医保药品名称">
			</div>
			<div class="btn-group">
				<label>批准文号：</label>
			</div>
			<div class="btn-group">
				<input id="txt_pzwh" type="text" style="width:200px; height:20px;" class="form-control form-an" placeholder="医保批准文号">
			</div>
			<div class="btn-group">
				<label>生产企业：</label>
			</div>
			<div class="btn-group">
				<input id="txt_scqy" type="text" style="width:200px; height:20px;" class="form-control form-an" placeholder="医保生产企业">
			</div>
			<div class="btn-group">
				<input type="button" id="btn_searchyb" class="btn btn-primary" value="查询" />
			</div>
			<div class="btn-group">
				<input type="button" id="btn_save" class="btn btn-primary" value="对码" />
			</div>
		</div>
		@*<table class="form">
			<tr>
				<th class="formTitle">药品代码：</th>
				<td class="formValue" colspan="3">
					<input id="txt_gjybdm" type="text" style="width:300px;" class="form-control form-an" placeholder="药品代码">
				</td>

				<td class="formValue" colspan="2">
					<span><input type="button" id="btn_searchyb" class="btn btn-primary" style="width:36%;margin-left: 10%;" value="查询" /></span>
					<span><input type="button" id="btn_save" class="btn btn-primary" style="width:36%;margin-left: 10%;" value="对码" /></span>

				</td>
				<th class="formTitle"></th>
				<td class="formValue"></td>
				<th class="formTitle"></th>
				<td class="formValue"></td>
			</tr>
		</table>*@
	</div>
	<div style="background-color: #fff; margin-top:5px;">
		<table id="gridJSMXList"></table>
	</div>
	@*<div style="background-color: #fff; margin-top:5px;">
			<input type="button" id="HZQD" class="btn btn-primary" style="width:60px;float:right;margin-right:10px;" value="汇总清单" />
				<input type="button" id="btn_cyjsd_print" class="btn btn-primary" style="width:60px;float:right;margin-right:10px;" value="医保结算单" />
		</div>*@
</form>

<script>
	$(function () {
		gridList();
		$("#btn_searchyb").click(function () {
			$('#gridJSMXList').jqGrid("clearGridData");//先清空明细
			btn_selectmx();
		});

		$("#btn_save").click(function () {

			btn_save();
		});
	});
	function gridList() {
        var $gridList = $("#gridList");
        $gridList.dataGrid({
            url: "@Url.Action("Getypxxlist")",
            height: 240,
			postData: getpostData(),
			rowNum: 10,
			rownumbers: true,
			unwritten: false,
			pager: "#gridPager",
			sortname: ' CreateTime desc',
			viewrecords: true,
            colModel: [
				{ label: "主键", name: "ypId", hidden: true, frozen: true, key: true },
				{ label: '药品名称', name: 'ypmc', width: 200, align: 'center',  sortable: false, frozen: true},
				{ label: "国家医保代码", name: "gjybdm", width: 180, align: 'center', sortable: false, frozen: true},
				{ label: "国家医保名称", name: "gjybmc", width: 200, align: 'center', sortable: false },
				{ label: '药品规格', name: 'ypgg', width: 110, align: 'center', sortable: false},
				{ label: '批准文号', name: 'pzwh', width: 140, align: 'center', sortable: false },
				{ label: '剂型', name: 'jxmc', width: 60, align: 'center', sortable: false },
				{ label: '生产厂家', name: 'ycmc', width: 180, align: 'center', sortable: false },
				{
					label: '自负性质', name: 'zfxz', width: 60, align: 'center', sortable: false, formatter: function (cellvalue, a, b) {
						switch (parseInt(b.zfxz)) {
						case @((int)EnumZiFuXingZhi.ZF):
                            return "@EnumZiFuXingZhi.ZF.GetDescription()";
						case @((int)EnumZiFuXingZhi.Jia):
							return "@EnumZiFuXingZhi.Jia.GetDescription()";
						case @((int)EnumZiFuXingZhi.Yi):
							return "@EnumZiFuXingZhi.Yi.GetDescription()";
						case @((int)EnumZiFuXingZhi.Bing):
                            return "@EnumZiFuXingZhi.Bing.GetDescription()";
						default:
                            return "";
                        }
					}
				},
				{ label: "医保代码", name: "ybdm", width: 110, align: 'center', sortable: false },
				{ label: '药品拼音', name: 'py', width: 100, align: 'center', sortable: false },
				{ label: "药品编码", name: "ypCode", width: 100, align: 'center', sortable: false }
				

			],
            
            onSelectRow_page: function (rowid) {
                btn_selectrow();
            },
            gridComplete: function (gridJszbList) {
                jszbList = null;
                if (gridJszbList && gridJszbList.rows) {
                    jszbList = gridJszbList.rows;
                }
            }
        });
	$gridList.jqGrid('setFrozenColumns');
        $("#btn_search").click(function () {
            $('#gridJSMXList').jqGrid("clearGridData");//先清空明细
            $gridList.jqGrid('setGridParam', {
                postData: getpostData(),
                page: 1,
			}).trigger('reloadGrid');
			$("#txt_gjybdm").val("");
			$("#txt_pzwh").val("");
			$("#txt_scqy").val("");
        });
	}


	//结算明细 jGrid声明
	$('#gridJSMXList').newtouchLocalDataGrid({
		height: $(window).height() - 520,
		caption: "医保药品信息",
		unwritten: false,
		colModel: [
			{ label: '国家医保代码', name: 'ypdm', width: 180, align: 'center' },
			{ label: '医保名称', name: 'zcmc', width: 200, align: 'center'},
			{ label: '医保药品名称', name: 'ybypmc', width: 80, align: 'center' },
			{ label: '规格', name: 'sjgg', width: 110, align: 'center' },
			{ label: '批准文号', name: 'pzwh', width: 130, align: 'center' },
			{ label: '剂型', name: 'sjjx', width: 60, align: 'center' },
			{ label: '生产企业', name: 'scqy', width: 180, align: 'center' },
			{ label: '甲乙类', name: 'jyl', width: 80, align: 'center' },
			{ label: '商品名称', name: 'spmc', width: 100, align: 'center' },
			{ label: '药品企业', name: 'ypqy', width: 180, align: 'center' },
			{ label: '医保剂型', name: 'ybjx', width: 80, align: 'center' },
			{ label: '备注', name: 'bz', width: 80, align: 'center' },
			{ label: '数据来源', name: 'sjly', width: 60, align: 'center' },
			{ label: '包装材质', name: 'bzcz', width: 80, align: 'center' },
			{ label: '最小包装数量', name: 'zxbzsl', width: 40, align: 'center' },
			{ label: '最小制剂单位', name: 'zxzjdw', width: 40, align: 'center' },
			{ label: '最小包装单位', name: 'zxbzdw', width: 80, align: 'center' },
			{ label: '编号', name: 'bh', width: 80, align: 'center' },


		],
		viewrecords: true,
		//ondblClickRow: function (row) {
		//	btn_clickrow();
		//}
	});

	function btn_selectmx() {

		var ypid = $("#gridList").jqGrid('getGridParam', 'selrow');
		if (!ypid) {
			$.modalMsg("请选择需要对码的药品信息", "warning", 1000);
			return false;
		}

		var pzwh = $("#txt_pzwh").val();
		var scqy = $("#txt_scqy").val();
		$('#gridJSMXList').jqGrid("clearGridData");
		$.najax({
			type: "POST",
			url: "@Url.Action("GetYpypxxlist")",
			data: { gjybdm: $("#txt_gjybdm").val(), ypmc: scqy, py:'' , pzwh: pzwh },
			dataType: "json",
			success: function (ajaxresp) {

				$('#gridJSMXList').newtouchLocalDataGrid(null, ajaxresp);
			}
		});
	}
	function btn_selectrow() {
		var gjybdm = $("#gridList").jqGridRowValue().gjybdm;
		var ypmc = $("#gridList").jqGridRowValue().ypmc;
		var yppy = $("#gridList").jqGridRowValue().py;
		var pzwh = $("#gridList").jqGridRowValue().pzwh;
		if (gjybdm != null && gjybdm!="0") {
			$("#txt_gjybdm").val(gjybdm)
		} else {
			$("#txt_gjybdm").val(ypmc);
		}

		$("#txt_pzwh").val("");
		$("#txt_scqy").val("");
		//每次单击，先清空上一条明细 和合计
		$('#gridJSMXList').jqGrid("clearGridData");
		$.najax({
			type: "POST",
			url: "@Url.Action("GetYpypxxlist")",
			data: { gjybdm: $("#txt_gjybdm").val(), ypmc: '', py: '', pzwh: '' },
			dataType: "json",
			success: function (ajaxresp) {
				$('#gridJSMXList').newtouchLocalDataGrid(null, ajaxresp);
			}
		});
	}


	//保存对码
	function btn_save() {

		var ypid = $("#gridList").jqGrid('getGridParam', 'selrow');
		if (!ypid) {
			$.modalMsg("请选择需要对码的药品信息", "warning", 1000);
			return false;
		}
		var ybid = $("#gridJSMXList").jqGrid('getGridParam', 'selrow');
		if (!ybid ){
			$.modalMsg("请选择医保药品信息", "warning", 1000);
			return false;
		}
		var ybxx = {
			ypdm: $("#gridJSMXList").jqGridRowValue().ypdm,
			zcmc: $("#gridJSMXList").jqGridRowValue().zcmc,
			jyl: $("#gridJSMXList").jqGridRowValue().jyl,
		};
		var ypId = $("#gridList").jqGridRowValue().ypId;
		var zfxz = ybxx.jyl == "甲" ? "4" : ybxx.jyl == "乙" ? "5" : ybxx.jyl == "丙" ? "6" : "1";
		$.najax({
			type: "POST",
			url: "@Url.Action("SaveYpYb")",
			data: { ybxx: ybxx, ypId: ypId},
			dataType: "json",
			success: function (data) {

				if (data != null && data !== "") {
					//gridList();
					$.modalAlert("该药品对码成功", 'success');
					//$("#txt_gjybdm").val("");
					//$('#btn_search').trigger('click');
					$("#txt_pzwh").val("");
					$("#txt_scqy").val("");
					var datarow = {
						gjybdm: $("#gridJSMXList").jqGridRowValue().ypdm,
						gjybmc: $("#gridJSMXList").jqGridRowValue().zcmc,
						zfxz: zfxz,
					};
					$("#gridList").jqGrid('setRowData', ypid, datarow);
				}
			}
		});
	}


	function getpostData() {
		return {
			keyword: $("#txt_keyword").val(), type: $('input:radio:checked').val()
		};
	}

</script>
